#ifndef INC_RAY_H
#define INC_RAY_H

#include "Vector3.h"

namespace gti
{

class AABB;
class Plane;
class Sphere;

class Ray
{
public:
	Ray();
	Ray(const vector3f &src, const vector3f &direction);

	void set(const vector3f &origin, const vector3f &direction);
	void computeRay(const vector3f &src, const vector3f &dst);
	void getPoint(float t,vector3f& point) const;

	// computes the distance from origin the the closest point to point
	void getClosestPoint(const vector3f& point, float& t) const;
	void getClosestPoint(const vector3f& point, vector3f& out) const;
	void getDistance(const vector3f& point, float& dist) const;

// fast intersect methods	
	int intersect(const AABB& aabb) const;

// precise intersect methods

	// ray sphere intersection 
	int intersect(const gti::vector3f& sphereCenter, float r, float& t0, float& t1) const;
	int intersect(const Sphere& sphere, float& t0, float& t1) const;
	// ray aabb intersection
	int intersect(const AABB &aabb,float &fT0,float &fT1) const;
	int intersect(const AABB& aabb, vector3f& point0, vector3f& point1) const;

	// ray plane intersection
	bool intersect (const Plane& plane, float &t) const;
	// ray triangle intersection (it doesnt check triangle normal)
	bool intersect (const vector3f& v0, const vector3f& v1, const vector3f& v2,
		float& t) const;

// render methods
	void render() const;
	
public:
// public member variables
	vector3f origin;
	vector3f dir;
};

};//namespace gti

#endif//INC_RAY_H
